using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace NetRosApp.Infrastructure.Interface
{
    //[Serializable]
    //[DebuggerDisplay("Count = {Count}")]
    //[ComVisible(false)]
    //public class EnumToDataSource<T> : Dictionary<int, String>
    //    {
    //        //T _loc = new T();
            
    //       public EnumToDataSource()
    //        {
    //            Type _loc = typeof(T);
    //        GetDataSource(_loc);
    //        }
    //        private void GetDataSource(Type _loc)
    //        {
                
    //            string[] names = Enum.GetNames(_loc);
    //            Array la = Enum.GetValues(_loc);
    //            foreach (T ime in la)
    //            {

    //                this.Add(Convert.ToInt16(Enum.Parse(_loc, Enum.GetName(_loc, ime))), Enum.GetName(_loc, ime));
    //            }
    //        }
          
          
    //    }


    public static class EnumUtils
    {
        public static System.Windows.Forms.BindingSource EnumToDataSource<T>()
        {
            Type enumType = typeof(T);

            // Can't use type constraints on value types, so have to do check like this
            if (enumType.BaseType != typeof(Enum))
                throw new ArgumentException("T must be of type System.Enum");

            Array enumValArray = Enum.GetValues(enumType);
            Dictionary<int, String> _di = new Dictionary<int, string>(enumValArray.Length);

            foreach (int var in enumValArray)
            {
                _di.Add(var,Enum.GetName(enumType,var));
            }
          
            //List<T> enumValList = new List<T>(enumValArray.Length);

            //foreach (int val in enumValArray)
            //{
            //    enumValList.Add((T)Enum.Parse(enumType, val.ToString()));
            //}
            System.Windows.Forms.BindingSource _bs = new System.Windows.Forms.BindingSource();
            _bs.DataSource = _di;
            return _bs;
        }
    }

}
